const winston = require('winston');
require('winston-daily-rotate-file');

exports.logger = winston.createLogger({
    level: 'debug',
    transports: [
        new winston.transports.Console({
            format: winston.format.simple()
        }),
        new winston.transports.DailyRotateFile({
            level: 'info',
            dirname: 'log',
            filename: '运行日志-%DATE%.log',
            datePattern: 'YYYY-MM-DD',
            maxSize: '1024k',
            format: winston.format.printf(info => {
                return `[${info.level}] ${info.message} at ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()}`;
            })
        })
    ],
    exceptionHandlers: [
        new winston.transports.File({
            dirname: 'log',
            filename: 'error.log'
        })
    ]
});